<template>
  <div class="app-container calendar-list-container">
    <div class="filter-container" style="margin-bottom:20px">
      <span style="margin-left:10px">用户手机号：</span>
      <el-input @keyup.enter.native="handleFilter" class="filter-item widht" :maxlength="11" placeholder="请输入用户11位有效手机号" v-model="queryPhone" clearable>
      </el-input>
      <el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-search" @click="handleFilter">搜索</el-button>
    </div>

    <el-table :data="zyInfoList" v-loading.body="listLoading" element-loading-text="Loading" border fit highlight-current-row>
      <el-table-column align="center" label='ID' min-width="80" prop="id"></el-table-column>
      <el-table-column align="center" label='用户ID' min-width="110" prop="userId"></el-table-column>
      <el-table-column align="center" label='考生性别' min-width="110" prop="sex"></el-table-column>
      <el-table-column align="center" label='文理分科' min-width="110" prop="division"></el-table-column>
      <el-table-column align="center" label='考生批次' min-width="110" prop="level"></el-table-column>
      <el-table-column align="center" label='考生省份' min-width="110" prop="province"></el-table-column>
      <el-table-column align="center" label='考生位次' min-width="110" prop="precedence"></el-table-column>
      <el-table-column align="center" label="操作" min-width="240">
        <template slot-scope="scope">
          <el-button size="small" type="primary" @click="handleUpdate(scope.row)">编辑
          </el-button>
        </template>
      </el-table-column>
    </el-table>  

    <div v-show="!listLoading" class="pagination-container">
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page.sync="filterParams.pageNo"
        :page-sizes="[5,10,20,30,50]" :page-size="filterParams.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total">
      </el-pagination>
    </div>


    <el-dialog title="编辑志愿用户信息" :visible.sync="editUsersDialog" center>
      <el-form :model="editForm" ref="ruleForm">
        <el-form-item label="文理分类" label-width="110px" prop="division">
          <el-input v-model="editForm.division" auto-complete="off" maxlength="10" placeholder="请输入考生类别"></el-input>
        </el-form-item>
        <el-form-item label="考生省份" label-width="110px" prop="province">
          <el-input v-model="editForm.province" auto-complete="off" maxlength="20" placeholder="请输入考生省份"></el-input>
        </el-form-item>
        <el-form-item label="考生性别" label-width="110px" prop="sex">
          <el-input v-model="editForm.sex" auto-complete="off" maxlength="10" placeholder="请输入考生性别"></el-input>
        </el-form-item>
        <el-form-item label="考生批次" label-width="110px" prop="level">
          <el-input v-model="editForm.level" auto-complete="off" maxlength="10" placeholder="请输入考生批次"></el-input>
        </el-form-item>
        <el-form-item label="考生位次" label-width="110px" prop="precedence">
          <el-input v-model="editForm.precedence" auto-complete="off" maxlength="10" placeholder="请输入考生位次"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="editUsersDialog = false">取 消</el-button>
        <el-button type="primary" @click="handleEdit">修 改</el-button>
      </div>
    </el-dialog>

  </div>  
</template>

<script>
import { queryUserInfoByMobile, updateZyInfoById } from '@/api/zyInfo'
export default {
  data() {
    return {
      queryPhone: '',
      editUsersDialog: false,
      filterParams: {
        mobile: null,
        pageNo: 1,
        pageSize: 10
      },
      listLoading: true,
      zyInfoList: [],
      editForm: {
        id: null,
        division: null, // 文理分科
        province: null, // 考生省份
        precedence: null, // 考生位次
        sex: null, // 考生性别
        level: null // 考生批次
      }
    }
  },
  mounted() {
    this.handleFilter()
  },
  methods: {
    // 点击‘搜索’按钮
    handleFilter() {
      this.listLoading = true
      this.filterParams.mobile = this.queryPhone
      queryUserInfoByMobile(this.filterParams).then(res => {
        if (res.code == 0) {
          this.zyInfoList = res.data.list
          this.total = res.data.total
        } else {
          this.$message({
            message: '暂无数据',
            type: 'info'
          })
        }
        this.listLoading = false
      })
    },
    // 点击‘编辑’按钮
    handleUpdate(item) {
      console.log('item', item)
      this.editForm = item
      this.editUsersDialog = true
    },
    // 点击‘修改’按钮
    handleEdit() {
      updateZyInfoById(this.editForm).then(res => {
        this.$message({
          message: res.message,
          type: res.message == '操作成功' ? 'success' : 'warning'
        })
        this.editUsersDialog = false
      })
    },
    handleSizeChange(val) {
      this.filterParams.pageSize = val
      this.handleFilter()
    },
    handleCurrentChange(val) {
      this.filterParams.pageNo = val
      this.handleFilter()
    }
  }
}
</script>

<style lang="scss" scoped>
  .app-container {
    padding: 20px;
  }
  .widht{
    width: 220px;
  }
</style>
